<?php


namespace App\Remote\Orm;


use GuzzleHttp\Exception\GuzzleException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class OrmShopRemote extends BaseOrmRemote
{
    /**
     * 获得门店基本信息
     * @return mixed
     * @throws GuzzleException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function getStoreByShopId(int $shopId)
    {
        return self::request(
            "GET",
            'internal/getStoreByShopId',
            ['shopId' => $shopId, 'brandId' => 1],
            null,
            'query'
        );
    }

    /**
     * 获得门店基本信息
     * @return mixed
     * @throws GuzzleException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function getStoreByShopCode(int $shopCode)
    {
        return self::request(
            "GET",
            'internal/getStoreByShopCode',
            ['shopCode' => $shopCode, 'brandId' => 1],
            null,
            'query'
        );
    }

    /**
     * 建店
     * @param string $shopName
     * @param string $shopMobile
     * @param string $userName
     * @param int $shopCode
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function createStore(string $shopName, string $shopMobile, string $userName, int $shopCode, int $regionCode, string $address, int $shopId, string $cityArea)
    {
        $params = [
            'shopName'       => $shopName,
            'phone'          => $shopMobile,
            'userName'       => $userName,
            'shopCode'       => $shopCode,
            'regionCode'     => $regionCode,
            'flag'           => '筹备中',
            'address'        => $address,
            'shopId'         => $shopId,
            'cityArea'       => $cityArea,
        ];

        return self::request(
            "POST",
            'internal/store/create',
            $params,
            null,
            'json'
        );
    }

    /**
     * 更新订货的shopId
     * @param int $shopCode
     * @param int $shopId
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function updateShopId(int $shopCode, int $shopId)
    {
        $params = [
            'shopId'   => $shopId,
            'shopCode' => $shopCode,
        ];

        return self::request(
            "POST",
            'internal/store/updateShopId',
            $params,
            null,
            'json'
        );
    }

    /**
     * 更新订货的标识
     * @param int $shopCode
     * @return array
     * @throws ContainerExceptionInterface
     * @throws GuzzleException
     * @throws NotFoundExceptionInterface
     */
    public static function updateFlag(int $shopCode): array
    {
        $params = [
            'shopCode' => $shopCode,
        ];
        return self::request(
            "POST",
            'internal/store/updateFlag',
            $params,
            null,
            'json'
        );
    }


}
